// import {
//     queryBillType,//单据类型条件查询
//     queryCmCostobject,//成本对象条件查询
//     queryCustomer,//客户条件查询
//     queryDefdoc,//品级条件查询
//     queryDefdoc2,//活鱼品规条件查询
//     queryIncome,//收款协议条件查询
//     queryMaterial,//物料条件查询
//     queryMaterialconvert,//物料辅计量单位条件查询
//     queryMeasdoc,//计量单位条件查询
//     queryOrgDept,//部门条件查询
//     queryOrgOrgs,//组织条件
//     queryPsndoc,//人员基本信息
//     queryResaCostcenter,//成本中心
//     queryStordoc,//品级条件查询
//     querySupplier,//供应商条件查询
// } from "@/api/nc-basic-info/index"

import ncBasicInfoApi from "@/api/nc-basic-info/index"

const getDefaultState = () => {
    return {
        BillType: [], //单据类型
        CmCostobject: [],//成本对象
        Customer: [],//客户
        Defdoc: [],//品级条件
        Defdoc2: [],//活鱼品规
        Income: [],//收款协议
        Material: [],//物料条件
        Materialconvert: [],//物料辅计量单位
        Measdoc: [],//计量单位
        OrgDept: [],//部门
        OrgOrgs: [],//组织
        Psndoc: [],//人员
        ResaCostcenter: [],//成本中心
        Stordoc: [],//仓库
        Supplier: [],//供应商
    }
}

const state = getDefaultState()

const mutations = {

    RESET_STATE: (state) => {
        Object.assign(state, getDefaultState())
    },

    SET_BillType: (state, data) => {
        state.BillType = data
    },

    SET_CmCostobject: (state, data) => {
        state.CmCostobject = data
    },

    SET_Customer: (state, data) => {
        state.Customer = data
    },

    SET_Defdoc: (state, data) => {
        state.Defdoc = data
    },

    SET_Defdoc2: (state, data) => {
        state.Defdoc2 = data
    },

    SET_Income: (state, data) => {
        state.Income = data
    },

    SET_Material: (state, data) => {
        state.Material = data
    },

    SET_Materialconvert: (state, data) => {
        state.Materialconvert = data
    },

    SET_Measdoc: (state, data) => {
        state.Measdoc = data
    },

    SET_OrgDept: (state, data) => {
        state.OrgDept = data
    },

    SET_OrgOrgs: (state, data) => {
        state.OrgOrgs = data
    },

    SET_Psndoc: (state, data) => {
        state.Psndoc = data
    },

    SET_ResaCostcenter: (state, data) => {
        state.ResaCostcenter = data
    },

    SET_Stordoc: (state, data) => {
        state.Stordoc = data
    },

    SET_Supplier: (state, data) => {
        state.Supplier = data
    },

}
const actions = {
    queryBillType({ commit }) {
        return new Promise((resolve, reject) => {
            ncBasicInfoApi.queryBillType({}).then(res => {
                const { data } = res
                localStorage.setItem("NcBillType", JSON.stringify(data || {}));
                commit('SET_BillType', data || {});
                console.log('SET_BillType', data)
            }).catch(error => {
                reject(error)
            })
        })
    },

    queryCmCostobject({ commit }) {
        return new Promise((resolve, reject) => {
            ncBasicInfoApi.queryCmCostobject({}).then(res => {
                const { data } = res
                localStorage.setItem("NcCmCostobject", JSON.stringify(data || {}));
                commit('SET_CmCostobject', data || {});
                console.log('SET_CmCostobject', data)
            }).catch(error => {
                reject(error)
            })
        })
    },

    queryCustomer({ commit }) {
        return new Promise((resolve, reject) => {
            ncBasicInfoApi.queryCustomer({}).then(res => {
                const { data } = res
                localStorage.setItem("NcCustomer", JSON.stringify(data || {}));
                commit('SET_Customer', data || {});
                console.log('SET_Customer', data)
            }).catch(error => {
                reject(error)
            })
        })
    },

    queryDefdoc({ commit }) {
        return new Promise((resolve, reject) => {
            ncBasicInfoApi.queryDefdoc({}).then(res => {
                const { data } = res
                localStorage.setItem("NcDefdoc", JSON.stringify(data || {}));
                commit('SET_Defdoc', data || {});
                console.log('SET_Defdoc', data)
            }).catch(error => {
                reject(error)
            })
        })
    },

    queryDefdoc2({ commit }) {
        return new Promise((resolve, reject) => {
            ncBasicInfoApi.queryDefdoc2({}).then(res => {
                const { data } = res
                localStorage.setItem("NcDefdoc2", JSON.stringify(data || {}));
                commit('SET_Defdoc2', data || {});
                console.log('SET_Defdoc2', data)
            }).catch(error => {
                reject(error)
            })
        })
    },

    queryIncome({ commit }) {
        return new Promise((resolve, reject) => {
            ncBasicInfoApi.queryIncome({}).then(res => {
                const { data } = res
                localStorage.setItem("NcIncome", JSON.stringify(data || {}));
                commit('SET_Income', data || {});
                console.log('SET_Income', data)
            }).catch(error => {
                reject(error)
            })
        })
    },

    queryMaterial({ commit }) {
        return new Promise((resolve, reject) => {
            ncBasicInfoApi.queryMaterial({}).then(res => {
                const { data } = res
                localStorage.setItem("NcMaterial", JSON.stringify(data || {}));
                commit('SET_Material', data || {});
                console.log('SET_Material', data)
            }).catch(error => {
                reject(error)
            })
        })
    },

    queryMaterialconvert({ commit }) {
        return new Promise((resolve, reject) => {
            ncBasicInfoApi.queryMaterialconvert({}).then(res => {
                const { data } = res
                localStorage.setItem("NcMaterialconvert", JSON.stringify(data || {}));
                commit('SET_Materialconvert', data || {});
                console.log('SET_Materialconvert', data)
            }).catch(error => {
                reject(error)
            })
        })
    },

    queryMeasdoc({ commit }) {
        return new Promise((resolve, reject) => {
            ncBasicInfoApi.queryMeasdoc({}).then(res => {
                const { data } = res
                localStorage.setItem("NcMeasdoc", JSON.stringify(data || {}));
                commit('SET_Measdoc', data || {});
                console.log('SET_Measdoc', data)
            }).catch(error => {
                reject(error)
            })
        })
    },

    queryOrgDept({ commit }) {
        return new Promise((resolve, reject) => {
            ncBasicInfoApi.queryOrgDept({}).then(res => {
                const { data } = res
                localStorage.setItem("NcOrgDept", JSON.stringify(data || {}));
                commit('SET_OrgDept', data || {});
                console.log('SET_OrgDept', data)
            }).catch(error => {
                reject(error)
            })
        })
    },

    queryOrgOrgs({ commit }) {
        return new Promise((resolve, reject) => {
            ncBasicInfoApi.queryOrgOrgs({}).then(res => {
                const { data } = res
                localStorage.setItem("NcOrgOrgs", JSON.stringify(data || {}));
                commit('SET_OrgOrgs', data || {});
                console.log('SET_OrgOrgs', data)
            }).catch(error => {
                reject(error)
            })
        })
    },

    queryPsndoc({ commit }) {
        return new Promise((resolve, reject) => {
            ncBasicInfoApi.queryPsndoc({}).then(res => {
                const { data } = res
                localStorage.setItem("NcPsndoc", JSON.stringify(data || {}));
                commit('SET_Psndoc', data || {});
                console.log('SET_Psndoc', data)
            }).catch(error => {
                reject(error)
            })
        })
    },

    queryResaCostcenter({ commit }) {
        return new Promise((resolve, reject) => {
            ncBasicInfoApi.queryResaCostcenter({}).then(res => {
                const { data } = res
                localStorage.setItem("NcResaCostcenter", JSON.stringify(data || {}));
                commit('SET_ResaCostcenter', data || {});
                console.log('SET_ResaCostcenter', data)
            }).catch(error => {
                reject(error)
            })
        })
    },

    queryStordoc({ commit }) {
        return new Promise((resolve, reject) => {
            ncBasicInfoApi.queryStordoc({}).then(res => {
                const { data } = res
                localStorage.setItem("NcStordoc", JSON.stringify(data || {}));
                commit('SET_Stordoc', data || {});
                console.log('SET_Stordoc', data)
            }).catch(error => {
                reject(error)
            })
        })
    },

    querySupplier({ commit }) {
        return new Promise((resolve, reject) => {
            ncBasicInfoApi.querySupplier({}).then(res => {
                const { data } = res
                localStorage.setItem("NcSupplier", JSON.stringify(data || {}));
                commit('SET_Supplier', data || {});
                console.log('SET_Supplier', data)
            }).catch(error => {
                reject(error)
            })
        })
    },
}

export default {
    namespaced: true,
    state,
    mutations,
    actions
}